<?php

class IndexController extends Zend_Controller_Action
{
    function preDispatch()
    {
		if(!$_SESSION['identity'])
        {
            $this->_redirect("/login");
        }
		
         //Make menu
         $mod_menu = new Db_Tables2_BDictMenu();
         $this->view->main_menu = $mod_menu->MenuDecolation();
    }
	
    function indexAction()
    {
        $params = $this->_request->getParams();
		
		if($params['date_start'])
		{
			$date_start = $params['date_start'];
		}else{
			$date_start = date("Y-m-d", mktime(1,1,1,date("m"),1,date("Y")));
		}
		
		$this->view->date_start = $date_start;
    	
		if($params['date_end'])
		{
			$date_end = $params['date_end'];
		}else{
			$date_end = date("Y-m-d");
		}
		
		$this->view->date_end = $date_end;
		
		$hxb_db = Zend_Registry::get('hxb_db');
		$select = $hxb_db->select();
		$select->from("auth_emp", array("username", "password"));
		$select->where("id = ?", $_SESSION['identity']['userid']);
		$row = $hxb_db->fetchRow($select);
		
		if($row)
		{
			if($row['password'] == md5(strtolower($row['username']).'123456'))
			{
				$this->view->redirect = 1;
			}
		}
		
		//get index info
		$mod_tables = new Db_Joins_TablesJoins();
		$mod_tables->date_start = $this->view->date_start = $date_start;
		$mod_tables->date_end = $this->view->date_end = $date_end;
		$this->view->index_info = $mod_tables->GetIndexInfo();
    }
}